﻿<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" >
<head>
<title>Pilot test of dojox.gfx3d.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
	@import "../../../dojo/resources/dojo.css";
	@import "../../../dijit/tests/css/dijitTests.css";
	@import "../../../dijit/themes/tundra/tundra.css";
</style>
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true"></script>
<script type="text/javascript">

dojo.require("dojox.gfx3d");

var angles = {x: 0, y: 0, z: 0};
var view = null;
var cube = null;

function moveMe(){
	var p = dojo.byId("action");
	var m = dojox.gfx3d.matrix;
	if(p.value == "Move to Back!"){
		console.debug(p.value);
		p.value = "Move to Front!";
		cube.setTransform(m.translate(20, 0, -120))
	}else{
		p.value = "Move to Back!";
		cube.setTransform(m.translate(50, 0, 150))
	}
	cube.invalidate();
	view.render();
};

makeObjects = function(){
	var surface = dojox.gfx.createSurface("test", 500, 500);
	view = surface.createViewport();
	var c = { bottom: {x: 0, y: 0, z: 0}, top :{x: 100, y: 100, z: 100} };
	var xaxis = [{x: 0, y: 0, z: 0}, {x: 200, y: 0, z: 0}];
	var yaxis = [{x: 0, y: 0, z: 0}, {x: 0, y: 200, z: 0}];
	var zaxis = [{x: 0, y: 0, z: 0}, {x: 0, y: 0, z: 200}];

	var m = dojox.gfx3d.matrix;

	view.createEdges(xaxis).setStroke({color: "red", width: 1});
	view.createEdges(yaxis).setStroke({color: "green", width: 1});
	view.createEdges(zaxis).setStroke({color: "blue", width: 1});

	view.createCube(c)
		.setFill({type: "plastic", finish: dojox.gfx3d.lighting.finish.dull, color: "blue"})
		.setStroke({color: "black", width: 1});

	cube = view.createCube(c)
		.setTransform(m.translate(50, 50, 150))
		.setFill({type: "plastic", finish: dojox.gfx3d.lighting.finish.dull, color: "lime"})
		.setStroke({color: "black", width: 1});

	var camera = dojox.gfx3d.matrix.normalize([
		m.cameraRotateXg(60), 
		m.cameraRotateYg(30),
		m.cameraTranslate(-200, -300, 0)
	]);

	view.applyCameraTransform(camera);
	view.setLights([{direction: {x: 10, y: 7, z: 5}, color: "white"}], 
			{color:"white", intensity: 2}, "white");
	view.render();

	// add the click event handler
	dojo.connect(dojo.byId("action"), "onclick", moveMe);
};

mdebug = function(matrix){
	var m = dojox.gfx3d.matrix.normalize(matrix);
	console.debug("xx: " + m.xx + ", xy: " + m.xy + " | xz:" + m.xz + " | dx:" + m.dx);
	console.debug("yx: " + m.yx + ", yy: " + m.yy + " | yz:" + m.yz + " | dy:" + m.dy);
	console.debug("zx: " + m.zx + ", zy: " + m.zy + " | zz:" + m.zz + " | dz:" + m.dz);
};

dojo.addOnLoad(makeObjects);

</script>
</head>
<body class="tundra">
	<h1>Pilot Test</h1>
	<p> The color of X, Y, Z axes are red, green, blue. One cube is in the center (0, 0, 0), click the button to move the other one back
	and forth, using this to test <em>dojox.gfx3d.drawer.conservative</em></p>
	<input id="action" type="button" value="Move to Back!"/>

<div id="test" style="width: 500px; height: 500px;"></div>
<p>That's all Folks!</p>
</body>
</html>
